package com.yc.jpyy.mobile.controller;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.service.RearviewMirrorService;


@Controller
@RequestMapping(value = "/rearviewmirror")
public class RearviewMirrorController extends BaseController {
	
	@Autowired
	private RearviewMirrorService rearviewMirrorService;

	private static Logger logger = LoggerFactory.getLogger(RearviewMirrorController.class);

	
	/**
	 * 获取某教练下某天课程的预约记录
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getAppointCourseByTeacher", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getStudentEvaluate(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {
			//教练ID
			String teacherId = request.getParameter("teacherId");
			//时间
			String time = request.getParameter("time");
			if(null !=teacherId && !teacherId.isEmpty()
					&& null !=time && !time.isEmpty()){
				Map<String, Object> valMap = new HashMap<String, Object>();
				valMap.put("teacherId", teacherId);
				valMap.put("time", time);
				response =  rearviewMirrorService.getAppointCourseByTeacher(valMap,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填参数!");
			}
		} catch (Exception e) {
			logger.info("getAppointCourseByTeacher："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("获取失败，请稍候重试！");
		} finally {
			return response.toJSON();
		}
	}
	
	
	/**
	 * 获取某教练的教学记录（教学日志的）
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getTeachDataByTeacher", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getTeachDataByTeacher(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {
			//教练ID
			String teacherId = request.getParameter("teacherId");
			//时间
			String time = request.getParameter("time");
			if(null !=teacherId && !teacherId.isEmpty()
					&& null !=time && !time.isEmpty()){
				Map<String, Object> valMap = new HashMap<String, Object>();
				valMap.put("teacherId", teacherId);
				valMap.put("time", time);
				response =  rearviewMirrorService.getTeachDataByTeacher(valMap,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填参数!");
			}
		} catch (Exception e) {
			logger.info("getTeachDataByTeacher："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("获取失败，请稍候重试！");
		} finally {
			return response.toJSON();
		}
	}
	
	
	/**
	 * 获取学员学时信息
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getClassInfoByStudent", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getClassInfoByStudent(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {
			//学院ID
			String studentId = request.getParameter("studentId");
			if(null !=studentId && !studentId.isEmpty()){
				Map<String, Object> valMap = new HashMap<String, Object>();
				valMap.put("studentId", studentId);
				response =  rearviewMirrorService.getCalssInfoByStudent(valMap,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填参数!");
			}
		} catch (Exception e) {
			logger.info("getCalssInfoByStudent："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("获取失败，请稍候重试！");
		} finally {
			return response.toJSON();
		}
	}
	
}
